package com.example.imtoken.core.base

import android.app.Application
import android.content.Intent
import android.view.Gravity
import androidx.core.content.ContextCompat
import androidx.multidex.MultiDex
import com.blankj.utilcode.util.*
import com.example.imtoken.R
import com.example.imtoken.core.App
import com.example.imtoken.core.utils.sp.SpHelps
import com.example.imtoken.modules.bug.BugActivity
import com.example.imtoken.room.base.AppDataBase

class BaseApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        //65535
        MultiDex.install(this)
        //toast初始化
        ToastUtils.getDefaultMaker().setBgColor(
            ContextCompat.getColor(
                this,
                R.color.black
            )
        ).setGravity(Gravity.CENTER, 0, 0).setTextColor(ContextCompat.getColor(this, R.color.white))

        AppDataBase.init(this)

        initCrash()

        // Log 总开关 true 开启 , false 关闭
        LogUtils.getConfig().isLogSwitch = true

        App.appCode = SPUtils.getInstance(SpHelps.APP).getString(SpHelps.APP_CODE, null)

    }

    private fun initCrash() {
        CrashUtils.init { crashInfo ->
            val intent = Intent(this, BugActivity::class.java)
            intent.putExtra("bug", crashInfo.toString())
            ActivityUtils.startActivity(intent)
        }
    }

}